/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.amazon.s3;

import java.util.logging.Level;
import java.util.logging.Logger;
import org.jets3t.service.S3Service;
import org.jets3t.service.S3ServiceException;
import org.jets3t.service.model.S3Bucket;
import org.jets3t.service.model.S3Object;

/**
 *
 * @author Ahmed Salem
 */
public class bucket {
    private String name;
    private String cre_date;
    private String ID;
    private String loca;

    private static  S3Bucket[] buckets = null;
    private static S3Service s3Service = null;
    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * @return the cre_date
     */
    public String getCre_date() {
        return cre_date;
    }

    /**
     * @return the ID
     */
    public String getID() {
        return ID;
    }

    /**
     * @return the loca
     */
    public String getLoca() {
        return loca;
    }

    //=========================================================================



    public static void create_bucket(String name) {
        //To store data in S3 you must first create a bucket, a container for objects.
        S3Bucket testBucket = null;
        try {
            testBucket = s3Service.createBucket(name);
        } catch (S3ServiceException ex) {
            System.out.println("Can't create bucket");
            Logger.getLogger(connect.class.getName()).log(Level.SEVERE, null, ex);
        }
        System.out.println("Created test bucket: " + testBucket.getName());
//

    }

    public static void delete_bucket(String name) {
        //To store data in S3 you must first create a bucket, a container for objects.
        try {
            s3Service.deleteBucket(name);
        } catch (S3ServiceException ex) {
            System.out.println("Can't create bucket");
            Logger.getLogger(connect.class.getName()).log(Level.SEVERE, null, ex);
        }
        //      System.out.println("Created test bucket: " + testBucket.getName());
//

    }
//==============================================================================

     public static void list_bucket() {
        // List all your buckets.
       
        try {
            buckets = s3Service.listAllBuckets();
        } catch (S3ServiceException ex) {
            Logger.getLogger(connect.class.getName()).log(Level.SEVERE, null, ex);
        }


    }
     //========================================================================
     public static void list_bucket_files(){


// List the object contents of each bucket.
        for (int b = 0; b < buckets.length; b++) {
            System.out.println("Bucket '" + buckets[b].getName() + "' contains:");

            // List the objects in this bucket.
            S3Object[] objects = null;
            try {
                objects = s3Service.listObjects(buckets[b]);
            } catch (S3ServiceException ex) {
                Logger.getLogger(connect.class.getName()).log(Level.SEVERE, null, ex);
            }

            // Print out each object's key and size.
            for (int o = 0; o < objects.length; o++) {
                System.out.println(" " + objects[o].getKey() + " (" + objects[o].getContentLength() + " bytes)");
            }
        }
     }


}
